package com.lyr.test;

import org.aspectj.lang.ProceedingJoinPoint;

public class MyAspect {

    // 前置通知
    public void beforeAdvice() {
        System.out.println("Before advice is running!");
    }

    // 后置通知
    public void afterAdvice() {
        System.out.println("After advice is running!");
    }

    // 返回后通知
    public void afterReturningAdvice(Object retVal) {
        System.out.println("After returning advice is running! Return value: " + retVal);
    }

    // 异常后通知
    public void afterThrowingAdvice(Throwable ex) {
        System.out.println("After throwing advice is running! Exception: " + ex.getMessage());
    }

    // 环绕通知
    public Object aroundAdvice(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("Around advice: Before method execution");
        Object result = null;
        try {
            result = joinPoint.proceed();
        } finally {
            System.out.println("Around advice: After method execution");
        }
        return result;
    }
}
